package com.doctor.windflower_doctor.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;

import com.doctor.windflower_doctor.R;

/**
 * <p>
 * 功能 加载动画
 * </p>
 * 
 * <p>
 * Copyright 北京亚普拓信息咨询服务有限公司 2014 All right reserved.
 * </p>
 * 
 * @author 皮勉 时间 2014年9月25日 下午12:07:41
 * @version 1.0 </br> 最后修改人 无
 */
public class LoadingDialog {
	private Dialog pd;
	private Activity mActivity;
	private TextView loadingText;
	private AnimationDrawable anim;
	private ImageView loadingImg;

	public LoadingDialog(Activity context) {
		mActivity = context;
		pd = new Dialog(context, R.style.dialog);
		View view = LayoutInflater.from(context).inflate(R.layout.loading_dialog, null);
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		loadingImg = (ImageView) view.findViewById(R.id.loading_img);
		loadingImg.setBackgroundResource(R.drawable.loading);
		anim = (AnimationDrawable) loadingImg.getBackground();
		anim.start();
		pd.setContentView(view);
	}

	public LoadingDialog setLoadingText(String text) {
		loadingText.setText(text);
		return this;
	}

	public void show() {
		if (!mActivity.isFinishing() && !pd.isShowing()) {
			pd.show();
		}
	}

	public void close() {
		if (!mActivity.isFinishing() && pd.isShowing()) {
			pd.dismiss();
		}
	}

	public boolean isShow() {
		return pd.isShowing();
	}

	public void setOnCancelListener(DialogInterface.OnCancelListener l) {
		pd.setOnCancelListener(l);
	}

}
